<script type="text/javascript">
		window.addEvent('domready',function(){
			var tabs = new MGFX.Tabs('#tabs','.tab-content',{
				autoplay: true,
				transitionDuration:500,
				slideInterval:3000,
				hover:true
			});
		});	
</script>
<?php
if ($_SESSION['rank'] < 4) {
    exit(Lang::getBackGlobal('wrong_permissions'));
}
/**
 * @author Martin Pernica
 * @copyright 2008
 */
echo '<h1>'.Lang::getBackGlobal('setting_title').'</h1>';
if (!empty($_POST['submit'])) {
    $web_title = Registry::get('db')->real_escape_string($_POST['web_title']);
    $web_subTitle = Registry::get('db')->real_escape_string($_POST['web_subTitle']);
    $web_charset = Registry::get('db')->real_escape_string($_POST['web_charset']);
    $web_author = Registry::get('db')->real_escape_string($_POST['web_author']);
    $web_description = Registry::get('db')->real_escape_string($_POST['web_description']);
    $web_keywords = Registry::get('db')->real_escape_string($_POST['web_keywords']);
    $language = Registry::get('db')->real_escape_string($_POST['language']);
    $allow_reg = intval($_POST['allow_reg']);
    //$article_per_page = intval($_POST['article_per_page']);
    $default_view = Registry::get('db')->real_escape_string($_POST['default_view']);
    $template = Registry::get('db')->real_escape_string($_POST['template']);
    $ranks = Registry::get('db')->real_escape_string($_POST['ranks']);
    $smiley = Registry::get('db')->real_escape_string($_POST['smiley']);
    $editor = Registry::get('db')->real_escape_string($_POST['editor']);

    $query = Registry::get('db')->query("UPDATE " . $GLOBALS['db_prefix'] .
        "setting SET web_title = '" . $web_title . "', web_subTitle = '" . $web_subTitle .
        "', web_author = '" . $web_author . "', web_description = '" . $web_description .
        "', web_keywords = '" . $web_keywords . "', language = '" . $language .
        "', allow_reg = '" . $allow_reg . "', default_view = '" . $default_view .
        "', web_charset = '" . $web_charset . "', template = '" . $template .
        "', ranks = '" . $ranks . "', smiley = '" . $smiley . "', editor = '" . $editor .
        "' WHERE id = '" . intval($_POST['id']) . "'") or die(Registry::get('db')->error);
    $log->write(8, 'com_setting', 'NOW()', 'User changed system setting', $_SESSION['id']);
    $event = 'roar.alert(\'Status\', \''.Lang::getBackGlobal('setting_save').'\');';
    array_push($Roar, $event);
}

$setting = Registry::get('db')->query("SELECT * FROM {prefix}setting");
$setting = $setting->fetch_array();

$setting['allow_reg'] = ($setting['allow_reg'] == 1) ? 'checked="checked"' : '';
$templates = dirlist('../templates');
$ranks = dirlist('../libs/ranks');
$smiley = dirlist('../libs/smiley');
$editors = dirlist('../plugins/editors');

echo '<form action="' . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'] .
    '" method="post">';
echo '

<ul id="tabs">
<li class="tab"><a href="#" id="one"><input type="button" value="' .
    Lang::getBackGlobal('setting_general') . '" /></a></li>
<li class="tab"><a href="#" id="two"><input type="button" value="' .
    Lang::getBackGlobal('setting_design') . '" /></a></li>
<li class="tab"><a href="#" id="three"><input type="button" value="'.Lang::getBackGlobal('setting_meta').'" /></a></li>
</ul>
<div id="settings">
';


echo '<div class="tab-content"><table style="color: black; width: 100%;">';
echo '<tr><td>ID sady nastavení : </td><td><input type="text" name="id" value="' .
    $setting['id'] . '" readonly="readonly" /></td></tr>';
echo '<tr><td>' . Lang::getBackGlobal('setting_webtitle') .
    ' : </td><td><input type="text" size="30" name="web_title" value="' . $setting['web_title'] .
    '" /></td></tr>';
echo '<tr><td>' . Lang::getBackGlobal('setting_description') .
    ' : </td><td><input type="text" size="30" name="web_subTitle" value="' . $setting['web_subTitle'] .
    '" /></td></tr>';
echo '<tr><td>' . Lang::getBackGlobal('setting_language') .
    ' : </td><td><select name="language" size="1">';
$arr_scandir = dirlist('../language');
foreach ($arr_scandir as $str_file) {
    $arr_lang = explode(".", $str_file);
    $str_lang = $arr_lang[0];
    if ($str_lang == $setting['language'])
        echo '<option value="' . $str_lang . '" selected="selected">' . $str_lang .
            '</option>';
    else
        echo '<option value="' . $str_lang . '" >' . $str_lang . '</option>';
}
echo '</select></td></tr>';
echo '<tr><td>' . Lang::getBackGlobal('setting_allow_reg') .
    ' : </td><td><input type="checkbox" ' . $setting['allow_reg'] .
    ' name="allow_reg" value="1" /></td></tr>';
echo '<tr><td>' . Lang::getBackGlobal('setting_default_view') .
    ' : </td><td><input type="text" size="30" name="default_view" value="' . $setting['default_view'] .
    '" /></td></tr>';
echo '<tr><td>' . Lang::getBackGlobal('setting_charset') .
    ' : </td><td><input type="text" size="30" name="web_charset" value="' . $setting['web_charset'] .
    '" /></td></tr>';
echo '</table></div><div class="tab-content"><table style="color: black; width: 100%;">';
echo '<tr><td>' . Lang::getBackGlobal('setting_template') .
    ' : </td><td><select name="template" size="1">';
for ($i = 0; !empty($templates[$i]); $i++) {
    if ($templates[$i] != '404.php') {
        if ($templates[$i] == $setting['template']) {
            echo '<option value="' . $templates[$i] . '" selected="selected">' . $templates[$i] .
                '</option>';
        } else {
            echo '<option value="' . $templates[$i] . '" >' . $templates[$i] . '</option>';
        }
    }
}
echo '</select></td></tr>';
echo '<tr><td>' . Lang::getBackGlobal('setting_template_rank') .
    ' : </td><td><select name="ranks" size="1">';
for ($i = 0; !empty($ranks[$i]); $i++) {
    if ($ranks[$i] == $setting['ranks']) {
        echo '<option value="' . $ranks[$i] . '" selected="selected">' . $ranks[$i] .
            '</option>';
    } else {
        echo '<option value="' . $ranks[$i] . '" >' . $ranks[$i] . '</option>';
    }
}
echo '</select></td></tr>';
echo '<tr><td>' . Lang::getBackGlobal('setting_setting_smiley') .
    ' : </td><td><select name="smiley" size="1">';
for ($i = 0; !empty($smiley[$i]); $i++) {
    if ($smiley[$i] == $setting['smiley']) {
        echo '<option value="' . $smiley[$i] . '" selected="selected">' . $smiley[$i] .
            '</option>';
    } else {
        echo '<option value="' . $smiley[$i] . '" >' . $smiley[$i] . '</option>';
    }
}
echo '</select></td></tr>';
echo '<tr><td>' . Lang::getBackGlobal('setting_text_editor') .
    ' : </td><td><select name="editor" size="1">';
for ($i = 0; !empty($editors[$i]); $i++) {
    if ($editors[$i] == $setting['editor']) {
        echo '<option value="' . $editors[$i] . '" selected="selected">' . $editors[$i] .
            '</option>';
    } else {
        echo '<option value="' . $editors[$i] . '" >' . $editors[$i] . '</option>';
    }
}
echo '</select></td></tr>';
echo '</table></div><div class="tab-content"><table style="color: black; width: 100%;">';
echo '<tr><td>'.Lang::getBackGlobal('setting_meta_desc').' : </td><td><input type="text" size="30" name="web_description" value="' .
    $setting['web_description'] . '" /></td></tr>';
echo '<tr><td>'.Lang::getBackGlobal('setting_meta_keyword').' : </td><td><input type="text" size="30" name="web_keywords" value="' .
    $setting['web_keywords'] . '" /></td></tr>';
echo '<tr><td>'.Lang::getBackGlobal('setting_meta_author').' : </td><td><input type="text" size="30" name="web_author" value="' .
    $setting['web_author'] . '" /></td></tr>';
echo '</table></div>';
echo '</div>';
echo '<br /><p><input type="submit" value="'.Lang::getBackGlobal('submit').'" name="submit" /></p></form>';
echo '<br /><h2><a href="index.php?p=status">'.Lang::getBackGlobal('status_title').'</a></h2>';
?>